package com.yingpai.fitness.dvp_2_0.main.activity.mine;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.yingpai.fitness.R;
import com.yingpai.fitness.dvp_2_0.common.activity.CommonActivity;
import com.yingpai.fitness.dvp_2_0.common.finalokgo.callback.Callback;
import com.yingpai.fitness.dvp_2_0.common.finalokgo.request.RequestType;
import com.yingpai.fitness.dvp_2_0.common.util.ActivityManager;
import com.yingpai.fitness.dvp_2_0.common.util.SharedPreferencesHelp;
import com.yingpai.fitness.dvp_2_0.common.util.constant.Contacts;
import com.yingpai.fitness.dvp_2_0.main.activity.LoginAndRegisterActivity;
import com.yingpai.fitness.dvp_2_0.main.bean.LogisticsBean;
import com.yingpai.fitness.dvp_2_0.main.util.DialogUtil;
import com.yingpai.fitness.dvp_2_0.main.util.constant.Constant;
import com.yingpai.fitness.dvp_2_0.main.util.constant.Url;
import com.yingpai.fitness.entity.wx.TokenBean;

import butterknife.OnClick;
import cn.jpush.android.api.JPushInterface;

/**
 * Created by ASUS on 2018/12/3.
 */

public class SettingActivity extends CommonActivity {

    private TokenBean tokenBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStatusFlag(Contacts.NORMAL_STATUS);
        setContentView(R.layout.dvp_2_0_activity_setting);
    }

    @Override
    protected void initView() {
        setTitle("设置");
        tokenBean = (TokenBean) SharedPreferencesHelp.getBean(Constant.TOKENBEAN);
    }

    @Override
    protected void initData() {

    }

    @Override
    @OnClick({R.id.user_security_relative_layout, R.id.user_feedback_relative_layout, R.id.clear_cache_relative_layout, R.id.logout})
    public void onViewClicked(View view) {
        super.onViewClicked(view);
        switch (view.getId()) {
            case R.id.user_security_relative_layout:
                startActivity(AccountSecurityActivity.class);
                break;
            case R.id.user_feedback_relative_layout:
                startActivity(FeedBackActivity.class);
                break;
            case R.id.clear_cache_relative_layout:
                break;
            case R.id.logout:
                DialogUtil.getInstance().showCenterDialog(this, R.layout.dialog_shop_pay_success);
                View dialog_logout = DialogUtil.getInstance().dialog_center_layout;
                dialog_logout.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        DialogUtil.getInstance().dialog_center.dismiss();
                    }
                });
                TextView title = dialog_logout.findViewById(R.id.title);
                title.setText("您确定要退出登录吗?");
                dialog_logout.findViewById(R.id.message).setVisibility(View.GONE);
                dialog_logout.findViewById(R.id.sure_cancel).setVisibility(View.VISIBLE);
                TextView sure = dialog_logout.findViewById(R.id.sure);
                TextView cancel = dialog_logout.findViewById(R.id.cancel);
                cancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        DialogUtil.getInstance().dialog_center.dismiss();
                    }
                });
                sure.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finalOkGo.requestEncrypt(RequestType.POSTENCRYPT, Contacts.HOST_SERVER + Url.LOGOUT, null, Url.LOGOUT, new Callback<LogisticsBean>() {
                            @Override
                            public void onSuccess(LogisticsBean baseResponse) {
                                if (baseResponse.getCode().equals(Constant.REQUEST_SUCCESS_0)) {

                                } else {
                                    showToast(baseResponse.getMessage() + "");
                                }
                            }
                        });
                        //删除别名
                        JPushInterface.deleteAlias(context,tokenBean.getId());
                        DialogUtil.getInstance().dialog_center.dismiss();
                        SharedPreferencesHelp.remove(Constant.TOKENBEAN);
                        ActivityManager.getActivityManager().popAllActivity();
                        startFinishActivity(LoginAndRegisterActivity.class);
                    }
                });
                break;
        }
    }
}
